import { BaseModel, sequelize, Sequelize } from "./basemodel.js";
import Users from "./users.js";

class Enrollments extends BaseModel {
	static init() {
		return super.init(
			{
				
				enrollment_id: { type: Sequelize.INTEGER, primaryKey: true, defaultValue: Sequelize.literal('DEFAULT') },
				course_name: { type:Sequelize.STRING , allowNull: false ,defaultValue: Sequelize.literal('DEFAULT') },
				student_id: { type:Sequelize.INTEGER  ,defaultValue: Sequelize.literal('DEFAULT') },
				course_id: { type:Sequelize.INTEGER  ,defaultValue: Sequelize.literal('DEFAULT') },
				teacher_id: { type:Sequelize.INTEGER  ,defaultValue: Sequelize.literal('DEFAULT') },
				enrollment_date: { type:Sequelize.DATEONLY , allowNull: false ,defaultValue: Sequelize.literal('DEFAULT') },
				status: { type:Sequelize.STRING  ,defaultValue: Sequelize.literal('DEFAULT') },
				created_at: { type:Sequelize.DATE , allowNull: false  },
				updated_at: { type:Sequelize.DATE , allowNull: false  }
			}, 
			{ 
				sequelize,
				
				tableName: "enrollments",
				modelName: "enrollments",
			}
		);
	}

	static associate() {
		this.belongsTo(Users, {
			foreignKey: 'teacher_id',
			as: 'teacher'
		});
	}
	
	static listFields() {
		return [
			'enrollment_id', 
			'student_id', 
			'course_id', 
			'course_name',
			'teacher_id',
			'enrollment_date', 
			'status', 
			'created_at', 
			'updated_at'
		];
	}

	static viewFields() {
		return [
			'enrollment_id', 
			'student_id', 
			'course_id', 
			'course_name',
			'teacher_id',
			'enrollment_date', 
			'status', 
			'created_at', 
			'updated_at'
		];
	}

	static editFields() {
		return [
			'enrollment_id', 
			'student_id', 
			'course_id', 
			'course_name',
			'teacher_id',
			'enrollment_date', 
			'status'
		];
	}

	
	static searchFields(){
		return [
			Sequelize.literal("enrollment_id LIKE :search"), 
			Sequelize.literal("status LIKE :search"),
		];
	}

	
	
}
Enrollments.init();
Enrollments.associate();
export default Enrollments;
